<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateWarehouse extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('warehouse')) {
            Schema::create('warehouse', function (Blueprint $table) {
                $table->id();
                $table->string('name')->default('')->comment('仓库名称');
                $table->string('w_number')->default('')->comment('仓库编号');
                $table->unsignedInteger('province_id')->default(0)->comment('省份ID');
                $table->string('province_name')->default('')->comment('省份名称');
                $table->unsignedInteger('city_id')->default(0)->comment('城市ID');
                $table->string('city_name')->default('')->comment('城市名称');
                $table->unsignedInteger('county_id')->default(0)->comment('区县ID');
                $table->string('county_name')->default('')->comment('区县名称');
                $table->string('address')->default('')->comment('详细地址');
                $table->unsignedInteger('create_user_id')->default(0)->comment('创建人ID');
                $table->integer('create_time')->nullable();
                $table->integer('update_time')->nullable();
            });
        }
        if (!Schema::hasTable('warehouse_user')) {
            Schema::create('warehouse_user', function (Blueprint $table) {
                $table->id();
                $table->unsignedInteger('warehouse_id')->default(0)->comment('仓库ID');
                $table->unsignedInteger('user_id')->default(0)->comment('管理员ID');
            });
        }
        if (!Schema::hasTable('warehouse_dept')) {
            Schema::create('warehouse_dept', function (Blueprint $table) {
                $table->id();
                $table->unsignedInteger('warehouse_id')->default(0)->comment('仓库ID');
                $table->unsignedInteger('dept_id')->default(0)->comment('部门ID');
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('warehouse');
        Schema::dropIfExists('warehouse_user');
        Schema::dropIfExists('warehouse_dept');
    }
}
